﻿<?php
   	include_once "../funciones.php";
    $con=conectar();
    $fallo=false;
   try {
          $con->beginTransaction();

        foreach($_POST as $borrar => $valor){
            echo $borrar;
            $sql="UPDATE INFORMES_PRESTAMOS SET ALTA = 0 WHERE OID_INF = ".$borrar;
            echo $sql;
            $stmt = $con->prepare($sql);
            $stmt->execute();
            $stmt = $con->prepare("commit");
            $stmt->execute();

            $sql="INSERT INTO LINEAS_PRESTAMOS_HISTORICO SELECT * FROM LINEAS_PRESTAMOS WHERE OID_INF = ".$borrar;
            echo $sql;
            $stmt = $con->prepare($sql);
            $stmt->execute();
            $stmt = $con->prepare("commit");
            $stmt->execute();



            $sql="DELETE FROM LINEAS_PRESTAMOS WHERE OID_INF = ".$borrar;
            echo $sql;
            $stmt = $con->prepare($sql);
            $stmt->execute();
            $stmt = $con->prepare("commit");
            $stmt->execute();


        }
   }catch(PDOException $e ) {
			echo "error: ".$e->GetMessage();
            $con->rollBack();
            $fallo=true;
            header( 'Location: borrarPrestamos.php?exito=2');
	}

    if($fallo==false)
        header( 'Location: borrarPrestamos.php?exito=1');



?>